import 'package:base/common/net/base_request.dart';
import 'package:dio/dio.dart';
import 'package:jskit/jskit.dart';

class TestReq extends BaseApiRequest {
  TestReq({required this.baseUrl, required this.targetUrl})
      : super(url: '/v1/face/imggen_sync', fromJson: (e) => e, method: DioMethod.post);
  final String baseUrl;
  final String targetUrl;

  @override
  // TODO: implement data
  Object? get data => {
    "model_id": "faceswap_v1",
    "base_img": {
      "url": baseUrl
    },
    "faces": [
      {
        "url": targetUrl,
        "index": 0,
        "base_index": 0
      }
    ]
  };
  @override
  Future<ApiResponse<dynamic>> execute({Dio? dio}) async {
    try {
      var ret = await DioUtil().request(
        path,
        parmas: method == DioMethod.get ? queryParameters : null,
        data: method == DioMethod.post ? data : null,
        dio: dio,
        options: option?.copyWith(sendTimeout: timeout, receiveTimeout: timeout),
        method: method,
      );

      var validatedData = validate(ret);
      if (validatedData == 200) {
        return ApiResponse(code: 200, data: ret.response['task']);
      } else {
        return handleException(ret);
      }
    } catch (e) {
      return ApiResponse(code: -1, msg: 'request error', e: e);
    }
  }
  @override
  dynamic convert(dynamic data) {
    return data;
  }
}
